<template>
  <div class="pd30 bind-record">
    <div class="panelWrap">
      <div class="title flex flexac flexjcsb fs14 cfff fwb pl p-r-20">
        <div>电梯基础信息</div>
      </div>
      <div class="bind-main">
        <div class="pl bind-top flex">
          <div class="flex flexac">
            <div class="flex flexac ">
              <span class="reg-name">注册代码：</span>
              <el-input v-model="parma.registerCode" class="reg-input" type="number" placeholder="请输入注册代码" />
            </div>
            <div class="rescueCode flex flexac m-l-20">
              <span class="res-name">位置码：</span>
              <el-input v-model="parma.rescueCode" class="res-input co-input" placeholder="请输入位置码" />
            </div>
            <div class="groupbtn flex m-l-40 ">
              <el-button class="flex flexac m-r-20 fs14" size="small" type="warning" @click="getBindElevator"><i class="co-i" /><span class="search1">查 询</span></el-button>
              <el-button class=" co-empty flexcenter m-l-25" type="info" @click="handleEmptySearch"><i class="iconfont icon-qingkong" />清 空</el-button>
            </div>
            <!-- <div class="flex flexac">
              <span class="nameText">地址：</span>
              <el-input v-model="parma.name" class="input" placeholder="请输入地址" />
            </div> -->
          </div>
          <!-- <div class="flex flexac m-t-15">
            <div class="groupbtn flex m-l-40 ">
              <el-button class="flex flexac m-r-20 fs14" size="small" type="warning" @click="getBindElevator"><i class="co-i" /><span class="search1">查 询</span></el-button>
              <el-button class=" co-empty flexcenter m-l-25" type="info" @click="handleEmptySearch"><i class="iconfont icon-qingkong" />清 空</el-button>
            </div>
          </div> -->
        </div>
        <div class="con-row flex flexac flexjcsb pl">
          <div>
            <el-button class="defaultbtn" type="primary" @click="handleRefresh"><i class="el-icon-refresh" :class="refresh?'goRefresh':''" />刷 新</el-button>

          </div>
          <div class="m-r-25 flex">
            <el-button class="defaultbtn" type="success" @click="handleSubmitFile"><i class="el-icon-success" />提交申请</el-button>

            <el-button class="defaultbtn" type="primary" @click="handleExportExcel"><i class="iconfont icon-wenjiandaochu" />导出</el-button>
            <div class="pre m-l-10">
              <el-button class="defaultbtn pre" type="primary" @click="handleSenior('field')"><i class="iconfont icon-lie" />字段
              </el-button>
              <div class="selectUl br1" :class="seniorSet.field?'showSelectUl':'hideSelectUl'">
                <div v-for="(item,i) in tablehead" :key="i" class="li">
                  <el-checkbox v-model="item.isShow">{{ item.label }}</el-checkbox>
                </div>
              </div>
            </div>
            <div class="pre m-l-10">
              <el-button class="defaultbtn" type="primary" @click="handleSenior('sortable')"><i class="iconfont icon-paixu" />排序</el-button>
              <div class="selectUl br1" :class="seniorSet.sortable?'showSelectUl':'hideSelectUl'">
                <div v-for="(item,i) in tablehead" v-if="item.isShow" :key="i" class="li">
                  <el-checkbox v-model="item.sortable">{{ item.label }}</el-checkbox>
                </div>
              </div>
            </div>
          </div>
        </div>
        <el-table
          id="applyRecordList"
          ref="applyRecordList"
          class="con-table"
          type="expand"
          :data="applyRecordList"
          style="width: 100%"
          highlight-current-row
          @selection-change="handleSelect"
        >
          <el-table-column width="60" type="selection" align="center" label="全选" />
          <template v-for="(item,i) in tablehead">
            <el-table-column v-if="item.isShow" :key="i" align="center" :width="item.width" :sortable="item.sortable" :show-overflow-tooltip="true" :prop="item.prop" :label="item.label" />
          </template>
          <el-table-column label="绑定状态" align="center" width="140">
            <template slot-scope="scope">
              <span :class="`status-${scope.row.bindState}`">
                {{
                  scope.row.bindState === 0 ? '未绑定' :
                  scope.row.bindState === 1 ? '已录入' :
                  scope.row.bindState === 2 ? '已申请' :
                  scope.row.bindState === 3 ? '已绑定' :
                  scope.row.bindState === 4 ? '已拒绝' : '未确认'
                }}
              </span>
            </template>
          </el-table-column>
          <!-- prop="name" -->
          <!-- <el-table-column label="基本操作" align="center">
            <template slot-scope="scope">
              <el-button class="defaultbtn" type="primary" size="mini" @click="handleEdit(scope.$index, scope.row)">
                <i class="el-icon-edit" />
                绑 定</el-button>
              <el-button type="danger" class="defaultbtn" @click="handleDeleteBtn(scope.$index, scope.row)"><i class="el-icon-delete-solid" />删除</el-button>
            </template>
          </el-table-column> -->
        </el-table>
        <el-pagination
          class="paginationWrap flex "
          :current-page="paging.currentPage"
          :page-sizes="[10, 40, 50, 100]"
          :page-size="paging.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="paging.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

  </div>
</template>

<script>

import { showNotice } from '@/utils/toolclass'
import { elevatorQueryList } from '@/api/elevator/elevator'
import { fetchApplyFiling } from '@/api/elevator/elevatorRelationship'

export default {
  name: 'AppilyRecord',
  props: {},
  data() {
    return {
      ids: [],
      paging: {
        currentPage: 1,
        pageSize: 10,
        // pageSizeArr1: [10, 20, 50, 100],
        total: 0
      },
      applyRecordList: [],
      parma: {
        bindState: '',
        id: '',
        registerCode: '',
        registerUnit: '',
        rescueCode: '',
        maintenanceUnitId: '',
        useUnitId: ''
      },
      refresh: false,
      seniorSet: {
        'field': false,
        'sortable': false
      },
      tablehead: [
        {
          index: 0,
          prop: 'rescueCode',
          label: '位置码',
          width: '80',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 1,
          prop: 'registerCode',
          label: '注册代码',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 2,
          prop: 'usePlaceName',
          label: '场所名称',
          width: '140',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 3,
          prop: 'useUnitName',
          label: '使用单位',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 4,
          prop: 'installAddress',
          label: '安装地址',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 5,
          prop: 'maintenancePerson1',
          label: '第一维保人',
          width: '100',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 6,
          prop: 'maintenancePerson1Phone',
          label: '第一维保人手机号码',
          sortable: false,
          fixed: true,
          isShow: true
        }
      ]
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getBindElevator()
  },
  mounted() {
    this.$storage.set('upUrl', JSON.stringify({ 'path': '/elevatordaDossier/elevatorFiles' }))
  },
  methods: {
    handleSubmitFile() {
      if (this.ids.length > 0) {
        this.$confirm('确定要提交申请吗？', '确认信息', {
          distinguishCancelAndClose: true,
          confirmButtonText: '保存',
          cancelButtonText: '取消'
        })
          .then(() => {
            fetchApplyFiling({ ids: this.ids }).then(res => {
              if (res.code === '000000') {
                showNotice('success', '提示', '提交成功')
                this.handleRefresh()
              } else {
                if (res.msg === '失败') {
                  showNotice('error', '提示', '提交失败')
                } else {
                  // showNotice('error', '提示', res.msg)
                }
              }
            })
          })
          .catch(action => {
            showNotice('success', '提示', '取消成功')
          })
      } else {
        showNotice('error', '提示', '请查询数据')
      }
    },
    handleSelect(val) {
      this.ids = val.map(item => item.id)
    },
    handleSenior(type) {
      if (type === 'field') {
        this.seniorSet.field = !this.seniorSet.field
        this.seniorSet.sortable = false
      }
      if (type === 'sortable') {
        this.seniorSet.field = false
        this.seniorSet.sortable = !this.seniorSet.sortable
      }
    },
    handleExportExcel() {
      // require.ensure([], () => {
      //   const { export_json_to_excel } = require("../excel/Export2Excel");
      //   const tHeader = ['制造商id', '制造商名称', '联系人', '联系人电话'];
      //   const filterVal = ['id', 'name', 'contacts', 'phone'];
      //   const data = this.formatJson(filterVal, this.applyRecordList);
      //   export_json_to_excel(tHeader, data, '制造商列表(' + formatDateTime().ymd) + ')';
      // })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    handleRefresh() {
      this.refresh = true
      this.getBindElevator()
      setTimeout(() => {
        this.refresh = false
      }, 1200)
    },
    getBindElevator() {
      elevatorQueryList(1, this.parma.id, this.parma.maintenanceUnitId, this.paging.currentPage, this.paging.pageSize, this.parma.registerCode, this.parma.registerUnit, this.parma.rescueCode, this.parma.useUnitId).then((res) => {
        if (res.code === '000000') {
          this.applyRecordList = res.data
          this.paging = {
            pageSize: res.pager.pageSize,
            currentPage: res.pager.pageIndex,
            total: res.pager.totalSize
          }
        }
      })
    },
    handleEmptySearch() {
      this.parma.registerCode = ''
      this.parma.rescueCode = ''
      this.parma.maintenanceUnitId = ''
      this.parma.useUnitId = ''
      this.getBindElevator()
    },
    handleSizeChange(val) {
      this.paging.pageSize = val
      this.getBindElevator()
    },
    handleCurrentChange(val) {
      this.paging.currentPage = val
      this.getBindElevator()
    }
  }
}
</script>
<style scoped lang="scss">
.bind-record {
  .bind-main {
    .status-0 {
      color: red;
      font-size: 16px;
      font-weight: 700;
    }
    .status-1 {
      color: darkgoldenrod;
      font-size: 16px;
      font-weight: 700;
    }
    .status-2 {
      color: blue;
      font-size: 16px;
      font-weight: 700;
    }
    .status-3 {
      font-size: 16px;
      font-weight: 700;
    }
    .status-4 {}
    .bind-top {
      height: 80px;
      background: #eeeeee;
      .reg-name {}
      .res-name {}
      .unit-name {}
      .reg-input {
        width: 200px;
      }
      .co-input {
        width: 180px !important;
      }
    }
  }
}
</style>
